package pdamh.view.utils;

import java.awt.Window;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

public class JFrameModal extends JFrame implements WindowListener {

	private static final long serialVersionUID = 1L;

	private Window jFrameParent;

	private boolean hideParent;

	public JFrameModal() {
		super();
	}

	public JFrameModal(Window parent) {
		this(parent, true);
	}
	
	public JFrameModal(Window parent, boolean hideParent) {
		this.jFrameParent = parent;
		this.hideParent = hideParent;
		this.addWindowListener(this);
	}

	public void setParentEnabled(boolean b) {
		if (jFrameParent != null) {
			jFrameParent.setEnabled(b);
			if (hideParent || b)
				jFrameParent.setVisible(b);
		}
	}

	public void windowActivated(WindowEvent e) {
	}

	public void windowClosed(WindowEvent e) {
	}

	public void windowClosing(WindowEvent e) {
		setParentEnabled(true);
	}

	public void windowDeactivated(WindowEvent e) {
	}

	public void windowDeiconified(WindowEvent e) {
	}

	public void windowIconified(WindowEvent e) {
	}

	public void windowOpened(WindowEvent e) {
		setParentEnabled(false);
	}

	public void dispose() {
		super.dispose();
		windowClosing(null);
	}

}
